package model.dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import model.Dao;
import model.entity.Marca;

public class MarcaDAO extends Dao {

    public static Marca insert_veiculo(Marca m) {
        try {

            int ID=0;

            String queryStr = "select MAX(ID_MARCA) FROM MARCA";
            Statement stmt = getConnection().createStatement();
            ResultSet rs = stmt.executeQuery(queryStr);
            if (rs.next()) {
                ID = rs.getInt(1);
                ID++;
            }
            rs.close();
            stmt.close();

            /*PreparedStatement idmax = getConnection().prepareStatement(
             "SELECT MAX(ID_MARCA) FROM MARCA");
             int id = idmax.executeUpdate();
             */
            PreparedStatement pstmt = getConnection().prepareStatement(
            "Insert Into MARCA (ID_MARCA, DESCRICAO) "
            + "Values(?, ?)");
            pstmt.setObject(1, ID);
            pstmt.setObject(2, m.getDescricao());

            pstmt.executeUpdate();
            //

            pstmt.close();
        } catch (Exception e) {
        }
        return m;
    }

    public static Marca update(Marca m) {
        try {
            PreparedStatement pstmt = getConnection().prepareStatement(
                    "Update Notas Set Nota = ?, Semestre = ?, Materia = ? "
                    + "Where id =?");
            pstmt.setObject(1, m.getId());
            pstmt.setObject(2, m.getDescricao());

            pstmt.executeUpdate();
            //

            pstmt.close();
        } catch (Exception e) {
        }
        return m;
    }

}